package com.lhl;

import com.lhl.build.ConcreteBuilder;
import com.lhl.build.Director;
import com.lhl.build.Product;
import com.lhl.chainbuild.build.Builder;
import com.lhl.chainbuild.build.ChainBuilder;
import com.lhl.lombokbuild.Product.ProductBuilder;

/**
 * 构建者模式
 * @author 刘翰林
 * @create 2024-09-20 0:46
 */
public class Main {
    public static void main(String[] args) {

        System.out.println("有指挥者：");
        buildDemo();
        System.out.println("*******************************");
        System.out.println("无指挥者：");
        chainBuildDemo();
        System.out.println("*******************************");
        System.out.println("Lombok自动创建构造者");
        lombokBuildDemo();
    }

    /**
     * 构造者模式链式调用【无指挥者，指挥权交给客户端】构建示例
     */
    public static void chainBuildDemo(){
        Builder builder = new ChainBuilder();
        com.lhl.chainbuild.build.Product instance = builder.buildCommon()
                .buildA()
                .buildB()
                .getInstance();

        System.out.println(instance);
    }

    /**
     * 有指挥者对象的构造器模式示例
     */
    public static void buildDemo(){
        Director director = new Director(new ConcreteBuilder());
        Product construct = director.Construct();

        System.out.println(construct);
    }

    public static void lombokBuildDemo(){

        ProductBuilder builder = com.lhl.lombokbuild.Product.builder();

        builder.partA("lombokA");
        builder.partB("lombokB");
        builder.common("lombokCommon");
        com.lhl.lombokbuild.Product product = builder.build();

        System.out.println(product);
    }
}
